package com.tqjc.execute.work.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tqjc.area.entity.Roller;
import com.tqjc.area.entity.SteelPlate;
import com.tqjc.area.service.RollerService;
import com.tqjc.common.consts.NormalConst;
import com.tqjc.execute.cache.TaskStatus;
import com.tqjc.execute.cache.entity.WorkStatus;
import com.tqjc.execute.consts.WorkConst;
import com.tqjc.execute.crane.entity.CraneInfo;
import com.tqjc.execute.crane.service.CraneInfoService;
import com.tqjc.execute.step.Move1Step;
import com.tqjc.execute.task.entity.RollerStockX;
import com.tqjc.execute.utils.HttpPLCUtils;
import com.tqjc.execute.utils.PublicResult;
import com.tqjc.execute.work.CraneWorkFactory;
import com.tqjc.execute.work.service.WorkService;
import com.tqjc.mes.entity.SteelInfo;
import com.tqjc.mes.entity.Test;
import com.tqjc.mes.service.SteelInfoService;
import com.tqjc.mes.service.TestService;
import com.tqjc.system.core.annotation.Log;
import com.tqjc.system.core.model.LogType;
import com.tqjc.system.core.redis.TaskRedisApi;
import com.tqjc.system.core.util.ShiroUtils;
import com.tqjc.system.core.util.SpringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.extractor.ExcelExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(path = "/work", produces = "application/json")
@Tag(name = "工作控制器", description = "工作控制")
@ApiResponses(@ApiResponse(responseCode = "200", description = "接口请求成功"))
@Slf4j
public class WorkController {

    @Resource
    CraneWorkFactory craneWorkFactory;

    @Resource
    WorkService workService;

    @Resource
    SteelInfoService steelInfoService;

    @Resource
    CraneInfoService craneInfoService;

    @Resource
    RollerService rollerService;

    @Resource
    TestService testService;

    @Resource
    TaskRedisApi taskRedisApi;

    @Resource
    TaskStatus taskStatus;

    @Value("${server_host}")
    private String serverHost;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/getRollerAndStockX")
    @ResponseBody
    public PublicResult getRollerAndStockX(@RequestParam Map<String, String> params) {
        try {
            String craneType = params.get("craneType").replace("\"", "");

            String rollerX= HttpPLCUtils.plcReadbc(restTemplate,serverHost,craneType,"辊道坐标X",false);
            String stock1X= HttpPLCUtils.plcReadbc(restTemplate,serverHost,craneType,"垛位1X",false);
            String stock2X="";
            if("11C北".equals(craneType)||"11C南".equals(craneType)){
                stock2X= HttpPLCUtils.plcReadbc(restTemplate,serverHost,craneType,"垛位2X",false);
            }
            RollerStockX rolStockX=new RollerStockX();
            rolStockX.setRollerX(rollerX);
            rolStockX.setStock1X(stock1X);
            rolStockX.setStock2X(stock2X);
            PublicResult result =PublicResult.ok(rolStockX);
            return result;
        }catch (Exception ex){
            ex.printStackTrace();
            log.error("获取辊道X坐标和垛位信息出现异常",ex);
            return PublicResult.fail(ex.getMessage());
        }

    }


    @RequestMapping("/updateSteelInfo")
    @ResponseBody
    public PublicResult updateSteelInfo(@RequestParam Map<String, String> params) {
        try {
            String craneType = params.get("craneType").replace("\"", "");
            String steelNoChecked = params.get("steelNoChecked").replace("\"", "");
            String steelLengthChecked = params.get("steelLengthChecked").replace("\"", "");
            String steelWidthChecked = params.get("steelWidthChecked").replace("\"", "");
            String steelThickChecked = params.get("steelThickChecked").replace("\"", "");
            log.info("用户{},在天车：{},更正了钢板号{}",ShiroUtils.getSessionUserName(),craneType,steelNoChecked);
            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程权限下才能操作更正功能");
            }


            List<SteelInfo> steels=null;
            //List<Test> steels=null;
            if(StringUtils.isNotEmpty(steelNoChecked)){
                steels= steelInfoService.selectByMatNo(steelNoChecked);


            }
            SteelPlate steelPlate=null;
            if(steels==null||(steels!=null&&steels.size()==0)){
                if(StringUtils.isNumeric(steelLengthChecked)&&StringUtils.isNumeric(steelWidthChecked)&&StringUtils.isNumeric(steelThickChecked)){
                    int length= Integer.parseInt(steelLengthChecked);
                    int width=Integer.parseInt(steelWidthChecked);
                    int thickness=Integer.parseInt(steelThickChecked);
                    if(length>18000||length<3000){
                        return PublicResult.fail("钢板长度超出范围，重输");
                    }
                    if(width>4000||width<1000){
                        return PublicResult.fail("钢板宽度超出范围，重输");
                    }
                    if(thickness>200||thickness<5){
                        return PublicResult.fail("钢板厚度超出范围，重输");
                    }
                    steelPlate=new SteelPlate();
                    steelPlate.setLength(Integer.parseInt(steelLengthChecked));
                    log.info("钢板长："+steelLengthChecked);
                    steelPlate.setWidth(Integer.parseInt(steelWidthChecked));
                    log.info("钢板宽："+steelWidthChecked);
                    steelPlate.setThickness(Integer.parseInt(steelThickChecked));
                    log.info("钢板厚："+steelThickChecked);
                }else {
                    return PublicResult.fail("钢板号不存在，重输或输入长宽厚");
                }
            }else if(steels!=null&&steels.size()>1){
                if(StringUtils.isNumeric(steelLengthChecked)&&StringUtils.isNumeric(steelWidthChecked)&&StringUtils.isNumeric(steelThickChecked)){
                    int length= Integer.parseInt(steelLengthChecked);
                    int width=Integer.parseInt(steelWidthChecked);
                    int thickness=Integer.parseInt(steelThickChecked);
                    if(length>18000||length<3000){
                        return PublicResult.fail("钢板长度超出范围，重输");
                    }
                    if(width>4000||width<1000){
                        return PublicResult.fail("钢板宽度超出范围，重输");
                    }
                    if(thickness>200||thickness<5){
                        return PublicResult.fail("钢板厚度超出范围，重输");
                    }
                    steelPlate=new SteelPlate();
                    steelPlate.setLength(Integer.parseInt(steelLengthChecked));
                    log.info("钢板长："+steelLengthChecked);
                    steelPlate.setWidth(Integer.parseInt(steelWidthChecked));
                    log.info("钢板宽："+steelWidthChecked);
                    steelPlate.setThickness(Integer.parseInt(steelThickChecked));
                    log.info("钢板厚："+steelThickChecked);
                }else{
                    return PublicResult.fail("钢板号有多个，重输或输入长宽厚");
                }

            } else if (steels!=null&&steels.size()==1) {
                steelPlate=new SteelPlate();
                steelPlate.setSteelId(steelNoChecked);
            }
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setSteelInfoWrite(steelPlate);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setIsSteelInfoChecked(true);
            PublicResult result =PublicResult.ok();
            return result;
        }catch (Exception ex){
            ex.printStackTrace();
            log.error("更正钢板信息出现异常",ex);
            return PublicResult.fail("更正钢板信息出现异常");
        }

    }

    @RequestMapping("/updateSteelNo")
    @ResponseBody
    @Log(type = LogType.work, name = "更正钢板号", memo = "更正了天车的钢板号")
    public PublicResult updateSteelNo(@RequestParam Map<String, String> params) {
        String steelNoChecked = params.get("steelNoChecked").replace("\"", "");
        try {
            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel("2#横移");
            if(modelRes){
                return PublicResult.fail("只有远程权限下才能操作更正功能");
            }
            log.info("用户{}更正了2号天车钢板号{}开始",ShiroUtils.getSessionUserName(),steelNoChecked);
            craneWorkFactory.getCraneWorkImpl("2#横移").getData().setSteelNoUpdated(steelNoChecked);
            craneWorkFactory.getCraneWorkImpl("2#横移").getData().setIsSteelNoChecked(true);
            PublicResult result =PublicResult.ok();
            log.info("用户{}更正了2号天车钢板号{}结束",ShiroUtils.getSessionUserName(),steelNoChecked);

            return result;
        }catch (Exception ex){
            ex.printStackTrace();
            log.error("用户{}更正了2号天车钢板号{}出现异常",ShiroUtils.getSessionUserName(),steelNoChecked,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }


    @RequestMapping("/taskPause")
    @ResponseBody
    @Log(type = LogType.work, name = "暂停自动化任务", memo = "暂停了天车自动化任务")
    public PublicResult taskPause(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车暂停按钮开始",ShiroUtils.getSessionUserName(),craneType);
            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程权限下才能操作任务暂停功能");
            }
            //清任务继续
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.4",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务继续",false);
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.3",HttpPLCUtils.dataTypeList.get("bool"),"TRUE","任务暂停",false);
            PublicResult result =PublicResult.ok();
            log.info("用户{}点击了{}天车暂停按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车暂停按钮出现异常",ShiroUtils.getSessionUserName(),craneType,ex);

            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/taskGoon")
    @ResponseBody
    @Log(type = LogType.work, name = "继续任务", memo = "天车任务继续运行")
    public PublicResult taskGoon(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车继续按钮开始",ShiroUtils.getSessionUserName(),craneType);
            //清暂停
            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程权限下才能操作任务继续功能");
            }
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.3",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务暂停",false);
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.4",HttpPLCUtils.dataTypeList.get("bool"),"TRUE","任务继续",false);
            Thread.sleep(1000);
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.4",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务继续",false);

            PublicResult result =PublicResult.ok();
            log.info("用户{}点击了{}天车继续按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车继续按钮出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/stopCraneTask")
    @ResponseBody
    @Log(type = LogType.work, name = "停止任务", memo = "天车任务停止")
    public PublicResult stopCraneTask(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车停止按钮开始",ShiroUtils.getSessionUserName(),craneType);

            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许操作任务停止");
            }

            craneWorkFactory.getCraneWorkImpl(craneType).getData().stopWork();
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"TRUE","任务中止",false);
            //清任务启动信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.2",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务启动",false);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setStartLogo(false);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setSemiAutoRunFlag(false);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setSemiAutoNowStep(0);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().updateSteelPlatesInStockByCrane(craneType); //清掉本垛在垛钢板
            //已吸取张数归零
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setSuckedSteelNum();
            PublicResult result =PublicResult.ok();
            log.info("用户{}点击了{}天车停止按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车停止按钮出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/taskAvoid")
    @ResponseBody
    @Log(type = LogType.work, name = "天车避让", memo = "天车执行避让动作")
    public PublicResult taskAvoid(@RequestParam Map<String, String> params) {
        String crane = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车避让按钮",ShiroUtils.getSessionUserName(),crane);

            Boolean modelRes = checkRemoteModel(crane);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许使用避让功能");
            }


            boolean autoRun= craneWorkFactory.getCraneWorkImpl(crane).getData().getStartLogo();
            boolean semiAutoRun=craneWorkFactory.getCraneWorkImpl(crane).getData().getSemiAutoRunFlag();
            if(!autoRun && !semiAutoRun){
                //清任务启动信号
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,crane,"DB20.8.2",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务启动",false);
                String stockNo= craneWorkFactory.getCraneWorkImpl(crane).getData().getStockNo();
                if("1".equals(stockNo)){
                    HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,crane,"DB20.9.1",HttpPLCUtils.dataTypeList.get("bool"),"TRUE","上层行车呼叫1",false);
                }else{
                    HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,crane,"DB20.9.2",HttpPLCUtils.dataTypeList.get("bool"),"TRUE","上层行车呼叫2",false);
                }
                return PublicResult.ok();
            }else {
                return PublicResult.fail("正在执行自动或半自动任务，不能避让");
            }


        }catch (Exception ex){
            log.error("用户{}点击了{}天车避让按钮,出现异常",ShiroUtils.getSessionUserName(),crane,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/rollerUnlock")
    @ResponseBody
    @Log(type = LogType.work, name = "辊道解锁", memo = "天车辊道解锁了")
    public PublicResult rollerUnlock(@RequestParam Map<String, String> params) {
        String crane = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车辊道解锁按钮开始",ShiroUtils.getSessionUserName(),crane);

            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(crane);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许进行辊道解锁");
            }

            CraneInfo craneInfo = craneInfoService.queryByName(crane);
            List<Integer> craneIds = new ArrayList<>();
            craneIds.add(craneInfo.getId());
            List<Roller> rollerList =rollerService.selectRollerByCraneId(craneIds);
            PublicResult result=null;
            if(rollerList!=null&&rollerList.size()>0){
                String[] lockArr=rollerList.get(0).getLockSignal().split("-");
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,crane,lockArr[1],HttpPLCUtils.dataTypeList.get("bool"),"FALSE",lockArr[0],true);
                result =PublicResult.ok();
            }else {
                result =PublicResult.fail("辊道不存在");
            }
            log.info("用户{}点击了{}天车辊道解锁按钮结束",ShiroUtils.getSessionUserName(),crane);

            return result;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车辊道解锁按钮,出现异常",ShiroUtils.getSessionUserName(),crane);
            return PublicResult.fail(ex.getMessage());
        }

    }



    @RequestMapping("/setMagnetBlock")
    @ResponseBody
    @Log(type = LogType.work, name = "磁块选择", memo = "天车选择了磁块")
    public PublicResult setMagnetBlock(@RequestParam Map<String, String> params) {

        String craneType = params.get("craneType").replace("\"", "");
        String magnetBlockNo = params.get("inputData").replace("\"", "");
        String isChecked = params.get("isChecked").replace("\"", "");

        log.info("用户{}点击了{}天车磁块选择按钮，磁块选择为：{}开始",ShiroUtils.getSessionUserName(),craneType,magnetBlockNo);

        try {
            //读模式，如果为远程手动  才允许选择磁块
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许进行磁块选择");
            }
            String boolVal="";
            if("true".equalsIgnoreCase(isChecked)){
                boolVal="TRUE";
            } else if ("false".equalsIgnoreCase(isChecked)) {
                boolVal="FALSE";
            }
            if("1".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁1",false);
            }else if("2".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.1",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁2",false);
            }else if("3".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.2",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁3",false);
            }else if("4".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.3",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁4",false);
            }else if("5".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.4",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁5",false);
            }else if("6".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.5",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁6",false);
            }else if("7".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.6",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁7",false);
            }else if("8".equals(magnetBlockNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.168.7",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"远程磁铁8",false);
            }
            log.info("用户{}点击了{}天车磁块选择按钮，磁块选择为：{}结束",ShiroUtils.getSessionUserName(),craneType,magnetBlockNo);
        } catch (Exception e) {
            log.error("用户{}点击了{}天车磁块选择按钮，磁块选择为：{}结束,出现异常",ShiroUtils.getSessionUserName(),craneType,magnetBlockNo);
            throw new RuntimeException(e);
        }

        //System.out.println("天车："+craneType+",磁块："+magnetBlockNo);
        PublicResult result =PublicResult.ok();

        return result;
    }

    @RequestMapping("/setMagnetValue")
    @ResponseBody
    @Log(type = LogType.work, name = "磁力选择", memo = "天车执行了磁力选择")
    public PublicResult setMagnetValue(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        String magnetValue = params.get("inputData").replace("\"", "");
        //System.out.println("天车："+craneType+",磁力："+magnetValue);
        //设置磁力
        try {
            log.info("用户{}点击了{}天车磁力选择按钮，磁力选择为：{}结束",ShiroUtils.getSessionUserName(),craneType,magnetValue);

            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许进行磁力选择");
            }
            int magVal= Integer.parseInt(magnetValue);
            if(magVal<0||magVal>100){
                return PublicResult.fail("磁力值必须为0到100");
            }
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.166",HttpPLCUtils.dataTypeList.get("int16"),magnetValue,"远程手动磁力给定",false);
            log.info("用户{}点击了{}天车磁力选择按钮，磁力选择为：{}结束",ShiroUtils.getSessionUserName(),craneType,magnetValue);

        } catch (Exception e) {
            log.error("用户{}点击了{}天车磁力选择按钮，磁力选择为：{},出现异常",ShiroUtils.getSessionUserName(),craneType,magnetValue);

            throw new RuntimeException(e);
        }

        PublicResult result =PublicResult.ok();

        return result;
    }

    @RequestMapping("/setStockNumValue")
    @ResponseBody
    public PublicResult setStockNumValue(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        String stockValue = params.get("inputData").replace("\"", "");
        try {

            //读模式，如果为远程手动  才允许设置磁力
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许设置堆放张数");
            }
            if(!"2#横移".equals(craneType)){
                Integer stockNumber = Integer.parseInt(stockValue);
                if(stockNumber>=1){
                    craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockPlaceNumber(stockNumber);
                    log.info("天车：{}设置堆放张数成功,堆放张数为：{}",craneType,stockNumber);
                }

            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        PublicResult result =PublicResult.ok();

        return result;
    }

    @RequestMapping("/startCraneTask")
    @ResponseBody
    @Log(type = LogType.work, name = "自动任务开始", memo = "天车自动化任务开始")
    public PublicResult startCraneTask(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车自动任务开始任务按钮====开始",ShiroUtils.getSessionUserName(),craneType);
            JSONObject inputData = JSON.parseObject(params.get("inputData"));

            Integer sheetNumber = inputData.getInteger("sheetNumber");
            String autoAlignFlag = params.get("autoAlignFlag");
            if("3#横移".equals(craneType)){
                String selectSensor = inputData.getString("selectSensor");
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"M3.1",HttpPLCUtils.dataTypeList.get("bool"),selectSensor,"传感器选择",false);

            }

            //Test Mes Oracle Start
            //com.tqjc.mes.entity.SteelInfo data= steelInfoService.selectByMatNo("B24308142000");
            //log.info(data.getMatNo()+","+data.getMatActThick()+","+data.getMatActLen()+","+data.getMatActWidth()+","+data.getMatActWt());
            //Test Mes Oracle End
            //读模式，如果为远程自动  才允许启动

            //判断当前是否正在执行任务
            PublicResult result = workService.checkIsReadyWork(craneType);
            if (!result.isSuccess()) {
                log.warn("当前天车有正在执行的自动任务");
                return result;
            }
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setStartLogo(true);

            //清半自动标志
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.6.1",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","半自动标志",false);

            String mode= HttpPLCUtils.plcReadbc(restTemplate,serverHost,craneType,"模式",false);
            if(!"5".equals(mode)){
                return PublicResult.fail("请切换到远程自动模式再启动");
            }

            PublicResult result2 = craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel();  //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。
            if (result2.isSuccess()) {
                return PublicResult.fail("天车处于吸板状态，不可启动");
            }
            if(!"2#横移".equals(craneType)){
                Integer stockNumber = inputData.getInteger("stockNumber");
                if(sheetNumber>stockNumber){
                    return PublicResult.fail("吸取张数不能大于堆垛张数");
                }
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockPlaceNumber(stockNumber);
            }
            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                Integer stockNo = inputData.getInteger("stock");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo+"");
            }
            PublicResult  result3=null;
            //设置对中机构
            if(StringUtils.isNotBlank(autoAlignFlag)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType, WorkConst.AUTO_ALIGN_DB,HttpPLCUtils.dataTypeList.get("bool"),autoAlignFlag,"自动对中屏蔽",false);
            }
            //清中止信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务中止",false);
            //清任务启动信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.2",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务启动",false);

            craneWorkFactory.getCraneWorkImpl(craneType).getData().setSuckedSteelNum();
            //更新状态值
            WorkStatus workStatus = taskStatus.getWorkStatusByCraneType(craneType);
            workStatus.setNowStatus("运行中");
            taskStatus.setWorkStatusByCraneType(craneType, workStatus);
            if (sheetNumber == 1) {
                result3=craneWorkFactory.getCraneWorkImpl(craneType).getData().startWork();
                log.info("用户{}启动了天车{}单板自动任务", ShiroUtils.getSessionUserName(),craneType);
            } else {
                result3=craneWorkFactory.getCraneWorkImpl(craneType).getData().startWork(sheetNumber);
                log.info("用户{}启动了天车{}多板自动任务", ShiroUtils.getSessionUserName(),craneType);
            }
            log.info("用户{}点击了{}天车自动任务开始任务按钮===结束",ShiroUtils.getSessionUserName(),craneType);

            return result3;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车自动任务开始任务按钮,出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            craneWorkFactory.getCraneWorkImpl(craneType).getData().setStartLogo(false);
            return PublicResult.fail("运行出现异常");
        }

    }

    @RequestMapping("/move1")
    @ResponseBody
    @Log(type = LogType.work, name = "移动辊道", memo = "半自动任务移动到辊道")
    public PublicResult move1Task(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车半自动任务移动辊道按钮开始",ShiroUtils.getSessionUserName(),craneType);

            JSONObject inputData = JSON.parseObject(params.get("inputData"));

            Integer sheetNumber = inputData.getInteger("sheetNumber");
            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
            if (!result2.isSuccess()) {
                return result2;
            }

//            PublicResult result3 = craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel(); //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。
//            if (result3.isSuccess()) {
//                return PublicResult.fail("吊具有板，不能执行此步骤");
//            }

            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                Integer stockNo = inputData.getInteger("stock");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo+"");
            }
            //清中止信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务中止",false);

            PublicResult result4=craneWorkFactory.getCraneWorkImpl(craneType).getData().move1();  // 半自动任务只能一次运输一块板

            log.info("用户{}点击了{}天车半自动任务移动辊道按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return PublicResult.ok();
        }catch (Exception ex){
            log.error("用户{}点击了{}天车半自动任务移动辊道按钮异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/suck2")
    @ResponseBody
    @Log(type = LogType.work, name = "执行吸板", memo = "半自动任务吸板动作")
    public PublicResult suck2Task(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            log.info("用户{}点击了{}天车半自动任务吸板按钮开始",ShiroUtils.getSessionUserName(),craneType);

            JSONObject inputData = JSON.parseObject(params.get("inputData"));

            Integer sheetNumber = inputData.getInteger("sheetNumber");
            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
            if (!result2.isSuccess()) {
                return result2;
            }

//            PublicResult result3 =  craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel();  //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。
//            if (result3.isSuccess()) {
//                return PublicResult.fail("吊具有板，不能执行此步骤");
//            }
            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                Integer stockNo = inputData.getInteger("stock");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo+"");
            }
            //清中止信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务中止",false);

            PublicResult result4=craneWorkFactory.getCraneWorkImpl(craneType).getData().suck2();  // 半自动任务只能一次运输一块板
            log.info("用户{}点击了{}天车半自动任务吸板按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result4;
        }catch (Exception ex){
            log.error("用户{}点击了{}天车半自动任务吸板按钮，出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/move3")
    @ResponseBody
    @Log(type = LogType.work, name = "移动到垛位", memo = "半自动任务移动到垛位")
    public PublicResult move3Task(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            JSONObject inputData = JSON.parseObject(params.get("inputData"));
            log.info("用户{}点击了{}天车半自动任务移动到垛位按钮开始",ShiroUtils.getSessionUserName(),craneType);


            Integer sheetNumber = inputData.getInteger("sheetNumber");
            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
            if (!result2.isSuccess()) {
                return result2;
            }
            //            PublicResult result3 =  craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel();  //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。
//            if (result3.isSuccess()) {
//                return PublicResult.fail("吊具有板，不能执行此步骤");
//            }



            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                Integer stockNo = inputData.getInteger("stock");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo+"");
            }
            //清中止信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务中止",false);

            PublicResult result4=craneWorkFactory.getCraneWorkImpl(craneType).getData().move3();  // 半自动任务只能一次运输一块板
            log.info("用户{}点击了{}天车半自动任务移动到垛位按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result4;


        }catch (Exception ex){
            log.error("用户{}点击了{}天车半自动任务移动到垛位按钮,出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }

    }

    @RequestMapping("/place4")
    @ResponseBody
    @Log(type = LogType.work, name = "执行放板", memo = "半自动任务放板动作")
    public PublicResult place4Task(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        try {
            JSONObject inputData = JSON.parseObject(params.get("inputData"));
            log.info("用户{}点击了{}天车半自动任务放板按钮开始",ShiroUtils.getSessionUserName(),craneType);

            Integer sheetNumber = inputData.getInteger("sheetNumber");
            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务

            if (!result2.isSuccess()) {
                return result2;
            }
//            PublicResult result3 =  craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel();  //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。

            //            PublicResult result3 =  craneWorkFactory.getCraneWorkImpl(craneType).getData().checkIsSuckedSteel();  //在停电情况下，如果恢复电后，判断天车是否吸板，如果是吸板，就不让启动。
//            if (result3.isSuccess()) {
//                return PublicResult.fail("吊具有板，不能执行此步骤");
//            }


            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                Integer stockNo = inputData.getInteger("stock");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo+"");
            }
            //清中止信号
            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB20.8.5",HttpPLCUtils.dataTypeList.get("bool"),"FALSE","任务中止",false);

            PublicResult result4=craneWorkFactory.getCraneWorkImpl(craneType).getData().place4();  // 半自动任务只能一次运输一块板
            log.info("用户{}点击了{}天车半自动任务放板按钮结束",ShiroUtils.getSessionUserName(),craneType);

            return result4;

        }catch (Exception ex){
            log.error("用户{}点击了{}天车半自动任务放板按钮,出现异常",ShiroUtils.getSessionUserName(),craneType,ex);
            return PublicResult.fail(ex.getMessage());
        }
    }


//    @Operation
//    @RequestMapping("/stopCraneTask")
//    @ResponseBody
//    @Log(type = LogType.work, name = "停止任务", memo = "天车自动任务停止任务")
//    public PublicResult stopCraneTask(@RequestParam Map<String, String> params) {
//        String craneType = params.get("craneType").replace("\"", "");
//        log.info("用户{}点击了{}天车自动任务停止任务按钮开始",ShiroUtils.getSessionUserName(),craneType);
//
//        //判断当前是否正在执行任务
//        PublicResult result = workService.checkIsEmptyWork(craneType);
//
//        if (!result.isSuccess()) {
//            return result;
//        }
//        try {
//            Boolean modelRes = checkRemoteModel(craneType);
//            if(modelRes){
//                return PublicResult.fail("只有远程模式才允许自动任务停止操作");
//            }
//
//        } catch (Exception e){
//            log.error("执行自动任务停止按钮出现异常",e);
//
//        }
//
//        craneWorkFactory.getCraneWorkImpl(craneType).getData().stopWork();
//        //已吸取张数归零
//        craneWorkFactory.getCraneWorkImpl(craneType).getData().setSuckedSteelNum();
//        log.info("用户{}点击了{}天车自动任务停止任务按钮结束",ShiroUtils.getSessionUserName(),craneType);
//
//        return PublicResult.ok("停止成功");
//    }


    @RequestMapping("/initStockNumValue")
    @ResponseBody
    public PublicResult initStockNumValue(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        log.info("天车：{},初始化堆放张数",craneType);
        PublicResult result =PublicResult.ok();

        try {
            if(!"2#横移".equals(craneType)){
                String suckedSteelNumStr =  "";
                int stockPlaceNumber = craneWorkFactory.getCraneWorkImpl(craneType).getData().getStockPlaceNumber();
                if(craneWorkFactory.getCraneWorkImpl(craneType).getData().getStartLogo()){
                    suckedSteelNumStr = craneWorkFactory.getCraneWorkImpl(craneType).getData().getSuckedSteelNum() + "";
                }
                Map map = new HashMap(3);
                if("11C南".equals(craneType) || "11C北".equals(craneType)){
                    String autoAlignFlag = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "自动对中屏蔽", false);
                    map.put("autoAlignFlag",Boolean.valueOf(autoAlignFlag));
                    String alignment1 = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "对中机构选择1", false);
                    String alignment2 = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "对中机构选择2", false);
                    String alignment3 = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "对中机构选择3", false);
                    String alignment4 = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "对中机构选择4", false);
                    map.put("alignment1",alignment1);
                    map.put("alignment2",alignment2);
                    map.put("alignment3",alignment3);
                    map.put("alignment4",alignment4);
                    String wideSteelFlag = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "中控超宽板选择", false);
                    map.put("wideSteelFlag",Boolean.valueOf(wideSteelFlag));
                    log.info("天车：{},自动对中标识点位为：{},超宽板选择点位为：{}",craneType,autoAlignFlag,wideSteelFlag);

                }
                if("3#横移".equals(craneType)){
                    String sensorSelectFlag = HttpPLCUtils.plcReadbc(restTemplate, serverHost, craneType, "传感器选择", false);
                    map.put("sensorSelectFlag",Boolean.valueOf(sensorSelectFlag));
                    log.info("天车：{},传感器选择标识为：{}",craneType,sensorSelectFlag);

                }

                map.put("stockPlaceNumber",stockPlaceNumber);
                map.put("suckedSteelNum",suckedSteelNumStr);
                result.setData(map);

            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


        return result;
    }



    @RequestMapping("/startAlign")
    @ResponseBody
    @Log(type = LogType.work, name = "一键对中", memo = "启动一键对中功能")
    public PublicResult startAlign(@RequestParam Map<String, String> params) {
        log.info("=====启动一键对中功能========");
        String craneType = params.get("craneType").replace("\"", "");
        PublicResult result =PublicResult.ok();
        Roller roller;


        if(!("11C南".equals(craneType) || "11C北".equals(craneType))){
            //dj车才需要执行一键对中功能
            return PublicResult.fail("当前天车不需要执行一键对中");
        }

        try {
            //读模式
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许启动一键对中功能");
            }

            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
            if (!result2.isSuccess()) {
                return result2;
            }

//            CraneInfo craneInfo = craneInfoService.queryByName(craneType);
//            List<Integer> craneIds = new ArrayList<>();
//            craneIds.add(craneInfo.getId());
//            List<Roller> rollerList =rollerService.selectRollerByCraneId(craneIds);
//
//            if(rollerList!=null&&rollerList.size()>0){
//                roller = rollerList.get(0);
//            } else {
//                log.info("当前天车【{}】启动一键对中按钮中，获取天车辊道信息失败",craneType);
//                result.setSuccess(false);
//                result.setMsg("辊道信息获取失败");
//                return result;
//            }
            craneWorkFactory.getCraneWorkImpl(craneType).getData().startAlign(craneType);
            result.setMsg("启动成功");
        } catch (Exception e) {
            log.error("启动一键对中功能失败",e);
            result.setSuccess(false);
            result.setMsg("启动失败");
        }


        return result;
    }


    @RequestMapping("/startEasyPlace")
    @ResponseBody
    @Log(type = LogType.work, name = "一键放料", memo = "启动一键放料功能")
    public PublicResult startEasyPlace(@RequestParam Map<String, String> params) {

        PublicResult result =PublicResult.ok();
        try {

            String craneType = params.get("craneType").replace("\"", "");
            String wideSteelFlag = params.get("wideSteelFlag");
            log.info("=====启动一键放料功能========,超宽板选择信号为：{}",wideSteelFlag);


            PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
            if (!result2.isSuccess()) {
                return result2;
            }
            String modeVal= HttpPLCUtils.plcReadbc(restTemplate,serverHost,craneType,"模式",false);

            if(!"7".equals(modeVal)){
                log.info("执行一键放料操作时，天车没有处于一键放料模式");
                result.setSuccess(false);
                result.setMsg("执行一键放料操作时，天车没有处于一键放料模式");
                return result;

            }

            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"M1999.0",HttpPLCUtils.dataTypeList.get("bool"),wideSteelFlag,"中控超宽板选择",false);
//
            if("11C南".equals(craneType)||"11C北".equals(craneType)){
                String stockNo = params.get("stockNo");
                craneWorkFactory.getCraneWorkImpl(craneType).getData().setStockNo(stockNo);
            }
            craneWorkFactory.getCraneWorkImpl(craneType).getData().startEasyPlace(craneType);



        } catch (Exception e){
            log.error("执行一键放料操作时，运行出现异常",e);
            result.setSuccess(false);
            result.setMsg("执行一键放料操作时，运行出现异常");
            return result;

        }

        log.info("=====完成一键放料功能========");
        return result;

    }


    @RequestMapping("/setAlignment")
    @ResponseBody
    @Log(type = LogType.work, name = "对中机构选择", memo = "天车选择对中机构")
    public PublicResult setAlignment(@RequestParam Map<String, String> params) {

        String craneType = params.get("craneType").replace("\"", "");
        String alignmentNo = params.get("inputData").replace("\"", "");
        String isChecked = params.get("isChecked").replace("\"", "");

        log.info("用户{}点击了{}天车对中机构选择按钮，对中机构选择为：{}开始",ShiroUtils.getSessionUserName(),craneType,alignmentNo);

        try {
            //读模式，如果为远程手动  才允许选择磁块
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许选择对中机构");
            }
            String boolVal="";
            if("true".equalsIgnoreCase(isChecked)){
                boolVal="TRUE";
            } else if ("false".equalsIgnoreCase(isChecked)) {
                boolVal="FALSE";
            }
            if("1".equals(alignmentNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB200.3.1",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"对中机构选择1",false);
            }else if("2".equals(alignmentNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB200.3.2",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"对中机构选择2",false);
            }else if("3".equals(alignmentNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB200.3.3",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"对中机构选择3",false);
            }else if("4".equals(alignmentNo)){
                HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType,"DB200.3.4",HttpPLCUtils.dataTypeList.get("bool"),boolVal,"对中机构选择4",false);
            };
            log.info("用户{}点击了{}天车对中机构选择按钮，对中机构选择为：{}结束",ShiroUtils.getSessionUserName(),craneType,alignmentNo);
        } catch (Exception e) {
            log.error("用户{}点击了{}天车对中机构选择按钮，对中机构选择为：{}异常",ShiroUtils.getSessionUserName(),craneType,alignmentNo);
            return PublicResult.fail("对中机构选择操作失败");
        }

        //System.out.println("天车："+craneType+",磁块："+magnetBlockNo);
        PublicResult result =PublicResult.ok();

        return result;
    }



    @RequestMapping("/setAutoAlignFlag")
    @ResponseBody
    @Log(type = LogType.work, name = "自动对中选择", memo = "天车设置自动对中标识")
    public PublicResult setAutoAlignFlag(@RequestParam Map<String, String> params) {
        String craneType = params.get("craneType").replace("\"", "");
        String isChecked = params.get("isChecked").replace("\"", "");

        PublicResult result2 = workService.checkSemiAutoIsReadyWork(craneType);  //是否正在执行子任务
        if (!result2.isSuccess()) {
            return result2;
        }



        log.info("用户{}点击了{}天车自动对中选择按钮，自动对中选择为：{}开始",ShiroUtils.getSessionUserName(),craneType,isChecked);

        PublicResult result =PublicResult.ok();
        try {
            //读模式，如果为远程手动  才允许选择磁块
            Boolean modelRes = checkRemoteModel(craneType);
            if(modelRes){
                return PublicResult.fail("只有远程模式才允许设置自动对中选择");
            }

            HttpPLCUtils.plcWritebcPlus(restTemplate,serverHost,craneType, WorkConst.AUTO_ALIGN_DB,HttpPLCUtils.dataTypeList.get("bool"),isChecked,"自动对中屏蔽",false);
        } catch (Exception e){
            log.error("用户{}点击了{}天车自动对中选择按钮，自动对中选择为：{}出现异常",ShiroUtils.getSessionUserName(),craneType,isChecked,e);
            return PublicResult.fail("自动对中选择操作失败");
        }

        return result;

    }

    private Boolean checkRemoteModel(String crane) throws Exception {
        try {
            String mode= HttpPLCUtils.plcReadbc(restTemplate,serverHost,crane,"模式",false);
            List<String> remoteModelVal = List.of("4","5","6","7");
            if( remoteModelVal.contains(mode)){
                return false;
            }

            return true;

        } catch (Exception e){
            log.info("{}:检验天车模式出现异常",crane,e);
            throw e;
        }
    }




}
